﻿#region Using Directives
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;
using NetROS.Tiers.Data.Bases;
using NetROS.Tiers.Services;
#endregion

namespace NetROS.Tiers.Web.Data
{
	/// <summary>
	/// Represents the DataRepository.VwPreostaloZaZatvaranjeProvider object that provides
	/// data to data-bound controls in multi-tier Web application architectures.
	/// </summary>
	[CLSCompliant(true)]
	[Designer(typeof(VwPreostaloZaZatvaranjeDataSourceDesigner))]
	public class VwPreostaloZaZatvaranjeDataSource : ReadOnlyDataSource<VwPreostaloZaZatvaranje>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeDataSource class.
		/// </summary>
		public VwPreostaloZaZatvaranjeDataSource() : base(new VwPreostaloZaZatvaranjeService())
		{
		}

		#endregion Constructors
		
		#region Properties
		
		/// <summary>
		/// Gets a reference to the VwPreostaloZaZatvaranjeDataSourceView used by the VwPreostaloZaZatvaranjeDataSource.
		/// </summary>
		protected VwPreostaloZaZatvaranjeDataSourceView VwPreostaloZaZatvaranjeView
		{
			get { return ( View as VwPreostaloZaZatvaranjeDataSourceView ); }
		}
		
		/// <summary>
		/// Gets or sets the name of the method or function that
		/// the VwPreostaloZaZatvaranjeDataSource control invokes to retrieve data.
		/// </summary>
		public new VwPreostaloZaZatvaranjeSelectMethod SelectMethod
		{
			get
			{
				VwPreostaloZaZatvaranjeSelectMethod selectMethod = VwPreostaloZaZatvaranjeSelectMethod.GetAll;
				Object method = ViewState["SelectMethod"];
				if ( method != null )
				{
					selectMethod = (VwPreostaloZaZatvaranjeSelectMethod) method;
				}
				return selectMethod;
			}
			set { ViewState["SelectMethod"] = value; }
		}
		
		#endregion Properties
		
		#region Methods

		/// <summary>
		/// Creates a new instance of the VwPreostaloZaZatvaranjeDataSourceView class that is to be
		/// used by the VwPreostaloZaZatvaranjeDataSource.
		/// </summary>
		/// <returns>An instance of the VwPreostaloZaZatvaranjeDataSourceView class.</returns>
		protected override BaseDataSourceView<VwPreostaloZaZatvaranje, Object> GetNewDataSourceView()
		{
			return new VwPreostaloZaZatvaranjeDataSourceView(this, DefaultViewName);
		}
		
		/// <summary>
        /// Creates a cache hashing key based on the startIndex, pageSize and the SelectMethod being used.
        /// </summary>
        /// <param name="startIndex">The current start row index.</param>
        /// <param name="pageSize">The current page size.</param>
        /// <returns>A string that can be used as a key for caching purposes.</returns>
		protected override string CacheHashKey(int startIndex, int pageSize)
        {
			return String.Format("{0}:{1}:{2}", SelectMethod, startIndex, pageSize);
        }
		
		#endregion Methods
	}
	
	/// <summary>
	/// Supports the VwPreostaloZaZatvaranjeDataSource control and provides an interface for
	/// data-bound controls to perform data operations with business and data objects.
	/// </summary>
	public class VwPreostaloZaZatvaranjeDataSourceView : ReadOnlyDataSourceView<VwPreostaloZaZatvaranje>
	{
		#region Declarations

		#endregion Declarations
		
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeDataSourceView class.
		/// </summary>
		/// <param name="owner">A reference to the VwPreostaloZaZatvaranjeDataSource which created this instance.</param>
		/// <param name="viewName">The name of the view.</param>
		public VwPreostaloZaZatvaranjeDataSourceView(VwPreostaloZaZatvaranjeDataSource owner, String viewName)
			: base(owner, viewName)
		{
		}
		
		#endregion Constructors
		
		#region Properties

		/// <summary>
		/// Gets a strongly-typed reference to the Owner property.
		/// </summary>
		internal VwPreostaloZaZatvaranjeDataSource VwPreostaloZaZatvaranjeOwner
		{
			get { return Owner as VwPreostaloZaZatvaranjeDataSource; }
		}

		/// <summary>
		/// Gets or sets the name of the method or function that
		/// the DataSource control invokes to retrieve data.
		/// </summary>
		internal new VwPreostaloZaZatvaranjeSelectMethod SelectMethod
		{
			get { return VwPreostaloZaZatvaranjeOwner.SelectMethod; }
			set { VwPreostaloZaZatvaranjeOwner.SelectMethod = value; }
		}

		/// <summary>
		/// Gets a strongly typed reference to the Provider property.
		/// </summary>
		internal VwPreostaloZaZatvaranjeService VwPreostaloZaZatvaranjeProvider
		{
			get { return Provider as VwPreostaloZaZatvaranjeService; }
		}

		#endregion Properties
		
		#region Methods
		
		/// <summary>
		/// Gets a collection of Entity objects based on the value of the SelectMethod property.
		/// </summary>
		/// <param name="count">The total number of rows in the DataSource.</param>
		/// <returns>A collection of Entity objects.</returns>
		protected override IList<VwPreostaloZaZatvaranje> GetSelectData(out int count)
		{
			Hashtable values = CollectionsUtil.CreateCaseInsensitiveHashtable(GetParameterValues());
			IList<VwPreostaloZaZatvaranje> results = null;
			// VwPreostaloZaZatvaranje item;
			count = 0;
			
			System.Int32? sp91_Konto;			System.Int32? sp91_Klijent;			System.Int32? sp91_IDOrg;			System.Int32? sp91_DILIP;			System.Int32? sp91_Storno;			System.Int32? sp90_Konto;			System.Int32? sp90_Klijent;			System.Int32? sp90_IDOrg;			System.Int32? sp90_DILIP;
			switch ( SelectMethod )
			{
				case VwPreostaloZaZatvaranjeSelectMethod.Get:
					results = VwPreostaloZaZatvaranjeProvider.Get(WhereClause, OrderBy, PageIndex, PageSize, out count);
                    break;
				case VwPreostaloZaZatvaranjeSelectMethod.GetPaged:
					results = VwPreostaloZaZatvaranjeProvider.GetPaged(WhereClause, OrderBy, PageIndex, PageSize, out count);
					break;
				case VwPreostaloZaZatvaranjeSelectMethod.GetAll:
					results = VwPreostaloZaZatvaranjeProvider.GetAll(StartIndex, PageSize, out count);
                    break;
				case VwPreostaloZaZatvaranjeSelectMethod.Find:
					results = VwPreostaloZaZatvaranjeProvider.Find(FilterParameters, OrderBy, StartIndex, PageSize, out count);
                    break;
				// Custom
				case VwPreostaloZaZatvaranjeSelectMethod.GetBy_IDKonto_IDMT_IDKlijent_DugiliPot_Storno:
					sp91_Konto = (System.Int32?) EntityUtil.ChangeType(values["@Konto"], typeof(System.Int32?));
					sp91_Klijent = (System.Int32?) EntityUtil.ChangeType(values["@Klijent"], typeof(System.Int32?));
					sp91_IDOrg = (System.Int32?) EntityUtil.ChangeType(values["@IDOrg"], typeof(System.Int32?));
					sp91_DILIP = (System.Int32?) EntityUtil.ChangeType(values["@DILIP"], typeof(System.Int32?));
					sp91_Storno = (System.Int32?) EntityUtil.ChangeType(values["@Storno"], typeof(System.Int32?));
					results = VwPreostaloZaZatvaranjeProvider.GetBy_IDKonto_IDMT_IDKlijent_DugiliPot_Storno(sp91_Konto, sp91_Klijent, sp91_IDOrg, sp91_DILIP, sp91_Storno, StartIndex, PageSize);
					break;
				case VwPreostaloZaZatvaranjeSelectMethod.GetBy_IDKonto_IDMT_IDKlijent_DugiliPot:
					sp90_Konto = (System.Int32?) EntityUtil.ChangeType(values["@Konto"], typeof(System.Int32?));
					sp90_Klijent = (System.Int32?) EntityUtil.ChangeType(values["@Klijent"], typeof(System.Int32?));
					sp90_IDOrg = (System.Int32?) EntityUtil.ChangeType(values["@IDOrg"], typeof(System.Int32?));
					sp90_DILIP = (System.Int32?) EntityUtil.ChangeType(values["@DILIP"], typeof(System.Int32?));
					results = VwPreostaloZaZatvaranjeProvider.GetBy_IDKonto_IDMT_IDKlijent_DugiliPot(sp90_Konto, sp90_Klijent, sp90_IDOrg, sp90_DILIP, StartIndex, PageSize);
					break;
				default:
					break;
			}

			if ( results != null && count < 1 )
			{
				count = results.Count;
			}
			
			return results;
		}
		
		#endregion Methods
	}

	#region VwPreostaloZaZatvaranjeSelectMethod
	
	/// <summary>
	/// Enumeration of method names available for the VwPreostaloZaZatvaranjeDataSource.SelectMethod property.
	/// </summary>
	public enum VwPreostaloZaZatvaranjeSelectMethod
	{
		/// <summary>
		/// Represents the Get method.
		/// </summary>
		Get,
		/// <summary>
		/// Represents the GetPaged method.
		/// </summary>
		GetPaged,
		/// <summary>
		/// Represents the GetAll method.
		/// </summary>
		GetAll,
		/// <summary>
		/// Represents the Find method.
		/// </summary>
		Find,
		/// <summary>
		/// Represents the GetBy_IDKonto_IDMT_IDKlijent_DugiliPot_Storno method.
		/// </summary>
		GetBy_IDKonto_IDMT_IDKlijent_DugiliPot_Storno,
		/// <summary>
		/// Represents the GetBy_IDKonto_IDMT_IDKlijent_DugiliPot method.
		/// </summary>
		GetBy_IDKonto_IDMT_IDKlijent_DugiliPot
	}
	
	#endregion VwPreostaloZaZatvaranjeSelectMethod
	
	#region VwPreostaloZaZatvaranjeDataSourceDesigner

	/// <summary>
	/// Provides design-time support in a design host for the VwPreostaloZaZatvaranjeDataSource class.
	/// </summary>
	public class VwPreostaloZaZatvaranjeDataSourceDesigner : ReadOnlyDataSourceDesigner<VwPreostaloZaZatvaranje>
	{
		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeDataSourceDesigner class.
		/// </summary>
		public VwPreostaloZaZatvaranjeDataSourceDesigner()
		{
		}

		/// <summary>
		/// Gets or sets the SelectMethod property.
		/// </summary>
		public new VwPreostaloZaZatvaranjeSelectMethod SelectMethod
		{
			get { return ((VwPreostaloZaZatvaranjeDataSource) DataSource).SelectMethod; }
			set { SetPropertyValue("SelectMethod", value); }
		}

		/// <summary>Gets the designer action list collection for this designer.</summary>
		/// <returns>The <see cref="T:System.ComponentModel.Design.DesignerActionListCollection"/>
		/// associated with this designer.</returns>
		public override DesignerActionListCollection ActionLists
		{
			get
			{
				DesignerActionListCollection actions = new DesignerActionListCollection();
				actions.Add(new VwPreostaloZaZatvaranjeDataSourceActionList(this));
				actions.AddRange(base.ActionLists);
				return actions;
			}
		}
	}

	#region VwPreostaloZaZatvaranjeDataSourceActionList

	/// <summary>
	/// Supports the VwPreostaloZaZatvaranjeDataSourceDesigner class.
	/// </summary>
	internal class VwPreostaloZaZatvaranjeDataSourceActionList : DesignerActionList
	{
		private VwPreostaloZaZatvaranjeDataSourceDesigner _designer;

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeDataSourceActionList class.
		/// </summary>
		/// <param name="designer"></param>
		public VwPreostaloZaZatvaranjeDataSourceActionList(VwPreostaloZaZatvaranjeDataSourceDesigner designer) : base(designer.Component)
		{
			_designer = designer;
		}

		/// <summary>
		/// Gets or sets the SelectMethod property.
		/// </summary>
		public VwPreostaloZaZatvaranjeSelectMethod SelectMethod
		{
			get { return _designer.SelectMethod; }
			set { _designer.SelectMethod = value; }
		}

		/// <summary>
		/// Returns the collection of <see cref="T:System.ComponentModel.Design.DesignerActionItem"/>
		/// objects contained in the list.
		/// </summary>
		/// <returns>A <see cref="T:System.ComponentModel.Design.DesignerActionItem"/>
		/// array that contains the items in this list.</returns>
		public override DesignerActionItemCollection GetSortedActionItems()
		{
			DesignerActionItemCollection items = new DesignerActionItemCollection();
			items.Add(new DesignerActionPropertyItem("SelectMethod", "Select Method", "Methods"));
			return items;
		}
	}

	#endregion VwPreostaloZaZatvaranjeDataSourceActionList

	#endregion VwPreostaloZaZatvaranjeDataSourceDesigner

	#region VwPreostaloZaZatvaranjeFilter

	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilter&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwPreostaloZaZatvaranje"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwPreostaloZaZatvaranjeFilter : SqlFilter<VwPreostaloZaZatvaranjeColumn>
	{
	}

	#endregion VwPreostaloZaZatvaranjeFilter

	#region VwPreostaloZaZatvaranjeExpressionBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlExpressionBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwPreostaloZaZatvaranje"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwPreostaloZaZatvaranjeExpressionBuilder : SqlExpressionBuilder<VwPreostaloZaZatvaranjeColumn>
	{
	}
	
	#endregion VwPreostaloZaZatvaranjeExpressionBuilder		
}

